We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Nginx and status code 409 ==> no body??

Hi,

I have a simple piece of code that works well on Apache, but does not return any body when using Nginx. It is a piece of code taken straight (mostly) from the official Phalcon documentation.

    $this->response->setStatusCode(409, 'Conflict')
                            ->setContentType('application/json', 'UTF-8')
                            ->setJsonContent(array('success' => false, 'error' => 'blabla'))
                            ->send();

    die();

Why is this happening? Is this a bug in Phalcon, or should we modify something in our Nginx server for this to work properly?

Thanks in advance!

Best regards,

If you do this in PHP, does it work?

header("409 Conflict");
header('Content-Type: application/json');
echo json_encode(array('success' => false, 'error' => 'blabla'));
edited Apr '15

Yes it does, it's the first thing I tested. Although the precise code I am using is:

http_response_code(409);
header('Content-type: application/json; charset=utf-8');
echo json_encode(array('success' => false, 'message' => 'Test http status code 409'));
die();

EDIT : we are using Phalcon 1.3.4 and nginx 1.6.2. Should we be using Phalcon 2.0.0 in production env? I see that it is marked as "stable" here https://phalcon.io/fr/download/windows



6.9k
Accepted
answer

Ok it seems it is due to nginx not sending some headers (CORS related) when response is 4xx.

For other people in that situation, you have to use headers_more module and recompile nginx.

Sorry for the trouble! (the catch was that the standard code was working when doing same-domain GET request, whereas the Phalcon code was tested via a cross-domain Ajax API)